    // 页面加载时收货区域为禁用状态且无收货地址，回显数据
    $(function () {
        if (localStorage.length > 0) {

            var customer = window.localStorage.getItem("customer");
            var obj = JSON.parse(customer);
            // 客户名称回显
            if (obj.customer_name != "") {
                $("#formControls").val(obj.customer_name).text(obj.customer_id);
            } else {
                $("#formControls").val("");
            }

            // 下单账号回显
            var account_data = {
                customerName: obj.customer_name,
                pageSize: 1,
                pageSize: 20
            };
            var succCallBack = function (data, status, response) {
                console.log(data);
                if (data.errorCode == "1") {
                    var jsonObj = data.list;
                    if (jsonObj == "") {
                        $("#orderAccount").html("<option>无数据</option> ");
                    } else {
                        console.log(jsonObj);
                        var optionstring = "<option value='0'>下单账号</option>";

                        for (var i = 0; i < jsonObj.length; i++) {
                            if (jsonObj[i].login_account == obj.login_account) {
                                var json = JSON.stringify(jsonObj[i]);
                                optionstring += "<option value='"+json+"' selected=\"true\">" + jsonObj[i].login_account + "</option>";
                            }
                        }
                        $("#orderAccount").html(optionstring);
                    }
                } else {
                    $("#orderAccount").html("<option>无数据</option> ");
                }
            };
            web.doAjax(root.condata.queryAccountTypeByCustomerNmae, 'post', account_data, succCallBack);

            // 收货地址回显
            var add = localStorage.getItem("address");
            var address = JSON.parse(add);

            var address_data = {
                memberId: obj.member_id,
                pageNum: 1,
                pageSize: 20
            };
            var succCallBack = function (data, status, response) {
                console.log(data);
                if (data.errorCode == "1") {
                    var jsonObj = data.list;
                    if (jsonObj == null) {
                        $("#address").html("<div class='clearfix pb-15'>无收货地址</div>" +
                            "<div class=\"up pt-5\">展开地址<img src=\"../../../img/up.png\" class=\"ml-10 icon_flip\"></div>" +
                            "<div class=\"up pt-5\">收起地址<img src=\"../../../img/up.png\" class=\"ml-10\"></div>");
                    } else {
                        console.log(jsonObj);
                        var optionstring = "";
                        for (var i = 0; i < jsonObj.length; i++) {
                            var json = JSON.stringify(jsonObj[i]);
                            if (address != "" && address != null && jsonObj[i].add_alias == address.add_alias) {
                                optionstring += "<div class='clearfix pb-15'><input name=\"address\" type=\"radio\" checked='checked' onclick='isChecked("+json+")'><span class=\"address_name\">"+jsonObj[i].add_alias+"</span><span class=\"user_name\">"+jsonObj[i].linkman+"</span><span class=\"address_detail\">"+jsonObj[i].detail_address+"</span><span class=\"user_phone\">"+jsonObj[i].mobile+"</span></div>";
                            } else {
                                optionstring += "<div class='clearfix pb-15'><input name=\"address\" type=\"radio\" onclick='isChecked("+json+")'><span class=\"address_name\">"+jsonObj[i].add_alias+"</span><span class=\"user_name\">"+jsonObj[i].linkman+"</span><span class=\"address_detail\">"+jsonObj[i].detail_address+"</span><span class=\"user_phone\">"+jsonObj[i].mobile+"</span></div>";
                            }
                        }
                        optionstring += "<div class=\"up pt-5\">展开地址<img src=\"../../../img/up.png\" class=\"ml-10 icon_flip\"></div>";
                        optionstring += "<div class=\"up pt-5\">收起地址<img src=\"../../../img/up.png\" class=\"ml-10\"></div>";
                        $("#address").html(optionstring);
                    }
                } else {
                    $("#address").html("<div class='clearfix pb-15'>无收货地址</div>" +
                        "<div class=\"up pt-5\">展开地址<img src=\"../../../img/up.png\" class=\"ml-10 icon_flip\"></div>" +
                        "<div class=\"up pt-5\">收起地址<img src=\"../../../img/up.png\" class=\"ml-10\"></div>");
                }
            };
            web.doAjax(root.condata.adminQueryMemberShoppingAddress, 'post', address_data, succCallBack);

            console.log(add);
        }

    });

    // 客户姓名联想
    function myFunction() {
        var formControls = $("#formControls").val();
        var user_data = {
            customerName: formControls,
            pageSize: 1,
            pageSize: 20
        };
        var succCallBack = function (data, status, response) {
            console.log(data);
            if (data.errorCode == "1") {
                var jsonObj = data.list;
                if (jsonObj == "") {
                    $("#tuan").html("<li>无数据</li> ");
                } else {
                    console.log(jsonObj);
                    var optionstring = "";
                    for (var i = 0; i < jsonObj.length; i++) {
                        optionstring += "<li onclick='relation(\"" + jsonObj[i].customer_id + "\",\"" + jsonObj[i].customer_name + "\")' data-align=\"" + jsonObj[i].customer_id + "\" > " + jsonObj[i].customer_name + "</li>";
                    }
                    $("#tuan").html(optionstring);
                }
            } else {
                // layer.msg(data.errorMessage, {icon: 6,time:1500});
                $("#tuan").html("<li>无数据</li> ");
            }
        };
        web.doAjax(root.condata.lenovoByCustomerName, 'post', user_data, succCallBack);
    }

    //客户姓名获取光标
    $("#formControls").focus(function () {
        $("#tuan").show()
        $("#address").html("<div class='clearfix pb-15'>无收货地址</div>" +
            "<div class=\"up pt-5\">展开地址<img src=\"../../../img/up.png\" class=\"ml-10 icon_flip\"></div>" +
            "<div class=\"up pt-5\">收起地址<img src=\"../../../img/up.png\" class=\"ml-10\"></div>");
    });
    $(document).bind("click", function (e) {
        //id为menu的是菜单，id为open的是打开菜单的按钮
        if ($(e.target).closest("#tuan").length == 0 && $(e.target).closest("#formControls").length == 0) {
            //点击id为menu之外且id不是不是open，则触发
            $("#tuan").hide()
        }
    });

    // 客户姓名点击后查询下单账号
    function relation(id, ce) {
        // 显示客户名称，隐藏客户id
        $("#formControls").val(ce).text(id);
        $("#tuan").hide();

        // 根据客户名称查询下单账号
        var formControls = $("#formControls").val();
        var account_data = {
            customerName: formControls,
            pageSize: 1,
            pageSize: 20
        };
        var succCallBack = function (data, status, response) {
            console.log(data);
            if (data.errorCode == "1") {
                var jsonObj = data.list;
                if (jsonObj == "") {
                    $("#orderAccount").html("<option>无数据</option> ");
                } else {
                    console.log(jsonObj);
                    var optionstring = "<option selected=\"\" value='0'>下单账号</option>";

                    for (var i = 0; i < jsonObj.length; i++) {
                        var json = JSON.stringify(jsonObj[i]);
                        optionstring += "<option value='"+json+"'>" + jsonObj[i].login_account + "</option>";
                    }
                    $("#orderAccount").html(optionstring);
                }
            } else {
                $("#orderAccount").html("<option>无数据</option> ");
            }
        };
        web.doAjax(root.condata.queryAccountTypeByCustomerNmae, 'post', account_data, succCallBack);
    }

    // 选中下单账号，查询收货地址列表
    function checkedSelect(value) {
        window.localStorage.setItem("customer", value);

        var obj = JSON.parse(value);
        console.log(obj.member_id);

        var address_data = {
            memberId: obj.member_id,
            pageNum: 1,
            pageSize: 20
        };
        var succCallBack = function (data, status, response) {
            console.log(data);
            if (data.errorCode == "1") {
                var jsonObj = data.list;
                if (jsonObj == null) {
                    $("#address").html("<div class='clearfix pb-15'>无收货地址</div>" +
                        "<div class=\"up pt-5\">展开地址<img src=\"../../../img/up.png\" class=\"ml-10 icon_flip\"></div>" +
                        "<div class=\"up pt-5\">收起地址<img src=\"../../../img/up.png\" class=\"ml-10\"></div>");
                } else {
                    console.log(jsonObj);
                    var optionstring = "";
                    for (var i = 0; i < jsonObj.length; i++) {
                        var json = JSON.stringify(jsonObj[i]);
                        optionstring += "<div class='clearfix pb-15'><input name=\"address\" type=\"radio\" onclick='isChecked("+json+")'><span class=\"address_name\">"+jsonObj[i].add_alias+"</span><span class=\"user_name\">"+jsonObj[i].linkman+"</span><span class=\"address_detail\">"+jsonObj[i].detail_address+"</span><span class=\"user_phone\">"+jsonObj[i].mobile+"</span></div>";
                    }
                    optionstring += "<div class=\"up pt-5\">展开地址<img src=\"../../../img/up.png\" class=\"ml-10 icon_flip\"></div>";
                    optionstring += "<div class=\"up pt-5\">收起地址<img src=\"../../../img/up.png\" class=\"ml-10\"></div>";
                    $("#address").html(optionstring);
                }
            } else {
                $("#address").html("<div class='clearfix pb-15'>无收货地址</div>" +
                    "<div class=\"up pt-5\">展开地址<img src=\"../../../img/up.png\" class=\"ml-10 icon_flip\"></div>" +
                    "<div class=\"up pt-5\">收起地址<img src=\"../../../img/up.png\" class=\"ml-10\"></div>");
             }
        };
        web.doAjax(root.condata.adminQueryMemberShoppingAddress, 'post', address_data, succCallBack);
    }

    // 把选中的地址转成字符串存起来
    function isChecked(str) {
        console.log(str);
        var string = JSON.stringify(str);
        window.localStorage.setItem("address", string);
    }


